
package com.kanjian.music;

import android.app.Application;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.kanjian.music.util.CommonUtil;
import com.kanjian.music.util.PlayerUtil;
import com.kanjian.music.volley.VolleyQueue;

/**
 * 自定义Application
 * 
 * @author xuyanjun@kanjian.com
 */
public class KanjianApplication extends Application {

    private static KanjianApplication context;

    public static String SID;

    public static int SCREEN_HEIGHT;

    public static int SCREEN_WIDTH;

    public static float SCREEN_DENSITY;

    public static final Gson GSON = new Gson();

    /**
     * 忽略除了@Expose注解以外成员的gson对象 仅在toJson时有效
     */
    public static final Gson GARDDISREGARD_EXPOSE_GSON = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation().create();

    public static KanjianApplication getContext() {
        return context;
    }

    public static String imei;

    @Override
    public void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(new UnCaughtExceptionHandler());
        // init imei
        TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
        imei = tm.getDeviceId();
        // init context
        if (context == null) {
            context = (KanjianApplication) getApplicationContext();
        }
        // 添加桌面图标
        if (CommonUtil.isFirstOpen()) {
            CommonUtil.addShortCut(context);
        }
        // init screen property
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        SCREEN_HEIGHT = displayMetrics.heightPixels;
        SCREEN_WIDTH = displayMetrics.widthPixels;
        SCREEN_DENSITY = displayMetrics.density;
        // init Volley
        VolleyQueue.init(context);
        // init SessionId
        SID = CommonUtil.getSessionId();
        
        // init localmusiclist
        PlayerUtil.paddingLocalMusicList();
    }

}
